package netspy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import utilities.IOHelp;

import netspy.dateien.*;
import netspy.dateien.MailList.MailType;

public class FileManager {
	
	public enum DateiFunc {
		WORD_BLACKLST,
		MAIL_BLACKLST,
		MAIL_WHITELST,
		MAIL_LOG,
		MAIN_CONFIG,
		DECODE_CONFIG
	}
		
	private HashMap<DateiFunc, Datei> files = new HashMap<DateiFunc, Datei>();
	
	public FileManager(String main_config_path) throws FileNotFoundException, IOException {
		
		this.files.put(DateiFunc.MAIN_CONFIG, new Config(new File(main_config_path)));
		
		// Initialize Configuration
		Config main_config = (Config)this.files.get(DateiFunc.MAIN_CONFIG);
		this.files.put (
				DateiFunc.DECODE_CONFIG,
				new Config( new File(main_config.getByKey("DECODE_CONFIG"))));
				
		this.files.put (
				DateiFunc.MAIL_BLACKLST,
				new MailList( new File(main_config.getByKey("MAIL_BLACKLST")), MailType.BLACK));
				
		this.files.put (
				DateiFunc.MAIL_WHITELST,
				new MailList( new File(main_config.getByKey("DECODE_CONFIG")), MailType.WHITE));
		
		this.files.put (
				DateiFunc.WORD_BLACKLST,
				new WordBlacklist( new File(main_config.getByKey("WORD_BLACKLST"))));
						
		// Initialize Log
		this.files.put (
				DateiFunc.MAIL_LOG,
				new Log( new File(main_config.getByKey("MAIL_LOG"))));
					
	}

	
	public void setDatei(DateiFunc func, Datei datei) {
		this.files.put(func, datei);
	}
	
	public Datei getDatei(DateiFunc func) {
		return this.files.get(func);
	}
}
